package com.zsd.android.rxjavalib.test;

import java.util.ArrayList;
import java.util.List;

/**
 * 被观察者的实现类
 */
public class ObservableImpl implements Observable {

    private List<Observer> observerList;

    public ObservableImpl() {
        observerList = new ArrayList<>();
    }

    @Override
    public void registerObserver(Observer observer) {
        observerList.add(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        observerList.remove(observer);
    }

    @Override
    public void notifyObservers() {
        for (Observer observer : observerList) {
            //在被观察者实现类中，通知所有观察者
            observer.changeAction("");
        }
    }
}
